package com.sun.exceptions;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.util.SaResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    // 全局异常拦截
    @ExceptionHandler(value = NotLoginException.class)

    public SaResult handlerNotLoginException(Exception e) {
        e.printStackTrace();
        return SaResult.notLogin();
    }
    @ExceptionHandler(value = NotPermissionException.class)

    public SaResult handlerNotPermissionException(Exception e) {
        e.printStackTrace();
        return SaResult.notPermission();
    }
    @ExceptionHandler

    public SaResult handlerException(Exception e) {
        e.printStackTrace();
        return SaResult.error(e.getMessage());
    }


}
